package cn.northsea.controller;

import cn.northsea.common.Result;
import cn.northsea.entity.SeekDz;
import cn.northsea.entity.SeekUser;
import cn.northsea.service.DzService;
import cn.northsea.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/dz")
public class DzController {
    @Autowired
    UserService userService;
    @Autowired
    DzService dzService;
    @GetMapping("/save")
    public Result save(String uname, Integer formid, Integer toid) {
        List<SeekDz> list= dzService.findByformIdtoid(formid,toid);
        SeekDz seekDz = new SeekDz();
        if (list.isEmpty())
        {
             SeekUser seekUser = userService.findByUserid(toid);
             seekDz.setToid(toid);
             seekDz.setUname(uname);
             seekDz.setTousername(seekUser.getUsername());
             seekDz.setUid(formid);
             dzService.save1(seekDz);
             dzService.save2(seekDz);
        }
        return null;
    }
}
